<template>
  <div class="main-pages">
    <div class="main-top">
      <span class="page-name">销售管理系统</span>
      <!-- 右侧头像，用户名称，下拉图标 -->
      <div class="page-right">
        <!-- 头像 -->
        <div class="user-profile">
          <img src="~@/assets/images/wx.png" alt="" />
        </div>
        <p class="user-name">{{ userName }}</p>
        <div class="user-down-menu">
          <span class="iconfont icon-JXC-shang down-menu-icon"></span>
          <!-- 下拉菜单 -->
          <div class="drop-down-menu">
            <div class="menu-box">
              <p
                v-for="item in dropDownMenu"
                :key="item.value"
                @click="clickMenu(item.value)"
              >
                {{ item.name }}
              </p>
            </div>
          </div>
        </div>
      </div>
      <!-- 帮助，售后，消息 -->
      <div class="top-icons">
        <span
          class="iconfont icon-JXC-bangzhu1 top-icon"
          v-MoveTips="'帮助中心'"
        ></span>
        <span
          class="iconfont icon-JXC-shouhou top-icon"
          v-MoveTips="'意见反馈'"
        ></span>
        <span
          class="iconfont icon-JXC-xiaoxi top-icon"
          v-MoveTips="'消息'"
        ></span>
      </div>
    </div>
    <div class="main-bottom" :class="{ retract: !navState }">
      <div class="left-nav">
        <p
          class="iconfont icon-JXC-zuo"
          :class="{ negation: !navState }"
          @click="navState = !navState"
        ></p>
        <div
          class="nav-list-item"
          :class="{ active: activeNav == item.pathName }"
          v-for="item in navList"
          :key="item.pathName"
          @click="switchNav(item)"
          v-MoveTips="item.name"
        >
          <span class="iconfont icon" :class="item.icon"></span>
          <span v-if="navState">{{ item.name }}</span>
        </div>
      </div>
      <div class="right-page">
        <div class="page-show">
          <router-view />
        </div>
      </div>
    </div>
    <!-- 个人信息弹窗 -->
    <PersonalInfo
      v-if="switchPersona"
      @close="switchPersona = false"
    ></PersonalInfo>
    <!-- 修改密码 -->
    <ChangePassword
      v-if="switchPassword"
      @close="switchPassword = false"
    ></ChangePassword>
  </div>
</template>

<script>
import { navList, dropDownMenu } from './main.js';
import { reactive, toRefs, onBeforeMount, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import PersonalInfo from './mainComponents/personalInfo/PersonalInfo.vue';
import ChangePassword from './mainComponents/changePassword/ChangePassword.vue';
export default {
  name: '',
  components: {
    PersonalInfo,
    ChangePassword
  },
  setup() {
    const router = useRouter();
    const route = useRoute();
    const data = reactive({
      navList, //导航列表
      dropDownMenu,
      activeNav: route.name, //默认根据url选中的导航
      navState: true, //导航展开收起
      switchPersona: false, //个人信息弹窗
      switchPassword: false, //修改密码
      userName: localStorage.getItem('LoginStatus')
    });
    // 切换导航
    const switchNav = (nav) => {
      data.activeNav = nav.pathName;
      router.push({
        name: nav.pathName
      });
    };
    // 下拉操作
    const clickMenu = (code) => {
      if (data.activeNav === code) return;
      if (code === 'exit') {
        ConfirmBox({
          title: '提示',
          content: '确认退出当前登录'
        })
          .then(() => {
            localStorage.removeItem('LoginStatus');
            router.push({
              name: 'login'
            });
          })
          .catch(() => {});
      } else if (code === 'personalCenter') {
        // data.switchPersona = true;   //弹窗形式
        switchNav({ pathName: code }); //页面形式
      } else if (code === 'changePassword') {
        data.switchPassword = true;
      }
    };
    return {
      clickMenu,
      switchNav,
      ...toRefs(data)
    };
  }
};
</script>
<style scoped lang="less">
.main-pages {
  position: relative;
  width: 100%;
  min-width: 1200px;
  height: 100%;
  padding-top: 30px;
  box-sizing: border-box;
  .main-top {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    height: 30px;
    width: 100%;
    box-sizing: border-box;
    box-shadow: 0px 1px 0px @HSD;
    padding: 0 20px;
    .page-name {
      float: left;
      height: 30px;
      line-height: 30px;
      font-size: 14px;
      color: @HSA;
    }
    .top-icons {
      float: right;
      line-height: 30px;
      margin-right: 10px;
      span {
        margin: 0 7px;
        cursor: pointer;
        font-weight: 700;
        color: @HSC;
        &:hover {
          color: @HSA;
        }
      }
    }
    .page-right {
      float: right;
      cursor: pointer;
      &:hover {
        .drop-down-menu {
          height: 140px;
        }
        .user-down-menu {
          .down-menu-icon {
            transform: rotate(0deg);
          }
        }
      }
      .drop-down-menu {
        position: absolute;
        right: 10px;
        height: 0px;
        top: 26px;
        z-index: 999;
        width: 120px;
        overflow: hidden;
        transition: 0.3s;
        .menu-box {
          margin: 7px 5px;
          background: #fff;
          box-shadow: 0px 1px 7px #cacaca;
          padding: 10px 0;
          p {
            font-size: 14px;
            padding: 0 16px;
            box-sizing: border-box;
            text-align: left;
            line-height: 30px;
            &:hover {
              background: @TSD;
            }
          }
        }
      }
      .user-profile {
        float: left;
        width: 26px;
        height: 26px;
        margin-top: 2px;
        position: relative;
        margin-right: 10px;
        cursor: pointer;
        img {
          width: 100%;
        }
      }
      .user-name {
        float: left;
        font-size: 14px;
        line-height: 30px;
        margin-right: 10px;
      }
      .user-down-menu {
        float: left;
        cursor: pointer;
        .down-menu-icon {
          float: right;
          font-size: 14px;
          line-height: 30px;
          transition: 0.3s;
          transform: rotate(180deg);
        }
      }
    }
  }
  .main-bottom {
    position: relative;
    height: 100%;
    width: 100%;
    padding-left: 150px;
    box-sizing: border-box;
    transition: 0.3s;
    &.retract {
      padding-left: 40px;
      .left-nav {
        width: 40px;
        .nav-list-item {
          padding-left: 0px;
        }
      }
    }
    .left-nav {
      transition: 0.3s;
      position: absolute;
      top: 0;
      left: 0;
      height: 100%;
      width: 150px;
      box-shadow: 1px 0px 1px #ddd;
      .icon-JXC-zuo {
        height: 40px;
        line-height: 40px;
        width: 100%;
        padding-left: 120px;
        box-sizing: border-box;
        margin-right: 20px;
        color: @TSH;
        font-weight: 700;
        cursor: pointer;
        transition: 0.3s;
        &.negation {
          transform: rotateY(180deg);
          padding-left: 15px;
          width: 40px;
          padding-left: 10px;
        }
        &:hover {
          background: @TSD;
        }
      }
      .nav-list-item {
        height: 40px;
        line-height: 40px;
        padding-left: 10px;
        cursor: pointer;
        font-size: 14px;
        transition: 0.3s;
        overflow: hidden;
        box-sizing: border-box;
        .icon {
          margin: 2px 15px 0 10px;
        }
        &.active {
          background: @TSE;
          color: @TSA;
          border-right: 4px solid @TSA;
        }
        &:hover {
          background: @TSE;
        }
      }
    }
    .right-page {
      height: 100%;
      width: 100%;
      background: @HSE;
      box-sizing: border-box;
      .page-show {
        background: #fff;
        height: 100%;
      }
    }
  }
}
</style>
